Stack & Queue

    Stack
StackTest.java
package collection.arraylist;
import java.util.ArrayList;
class MyStack{
private ArrayList<String> arrayStack=new ArrayList<String>();
public void push(String data) {
arrayStack.add(data);
}
public String pop() {
int len=arrayStack.size();
if(len==0) {
System.out.println(" .");
return null;
}
return (arrayStack.remove(len-1));
}
}
public class StackTest {
public static void main(String[] args) {
MyStack stack=new MyStack();
stack.push("A");
stack.push("B");
stack.push("C");
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
}
}
    Queue
QueueTest.java
package collection.arraylist;
import java.util.ArrayList;
class MyQueue{
private ArrayList<String> arrayQueue=new ArrayList<String>();
public void enQueue(String data) {
arrayQueue.add(data);
}
public String deQueue() {
int len=arrayQueue.size();
if(len==0) {
System.out.println(" .");
return null;
}
return (arrayQueue.remove(0));
}
}
public class QueueTest {
public static void main(String[] args) {
MyQueue queue=new MyQueue();
queue.enQueue("A");
queue.enQueue("B");
queue.enQueue("C");
System.out.println(queue.deQueue());
System.out.println(queue.deQueue());
System.out.println(queue.deQueue());
}
}